package handler

import (
	"github.com/gin-gonic/gin"
	"github.com/go-pay/gopay"
	"github.com/go-pay/gopay/wechat/v3"
	v1 "golang-sgg-daijia/api/v1"
	"golang-sgg-daijia/internal/service"
)

type CallbackHandler struct {
	*Handler
	paymentService service.PaymentService
}

func NewCallbackHandler(
	handler *Handler,
	paymentService service.PaymentService,
) *CallbackHandler {
	return &CallbackHandler{
		Handler:    handler,
		paymentService: paymentService,
	}
}

// Notify 微信支付回调
func (h *CallbackHandler) Notify(ctx *gin.Context) {
	err := h.paymentService.WxNotify(ctx, ctx.Request)
	if err != nil {
		v1.HandleSuccess(ctx, &wechat.V3NotifyRsp{Code: gopay.FAIL, Message: "失败"})
		return
	}
	v1.HandleSuccess(ctx, &wechat.V3NotifyRsp{Code: gopay.SUCCESS, Message: "成功"})
}

